package com.PopulateDB;

import java.util.Calendar;

public class PopulateUsers implements PopulateFormat{
	//private static MySQLDBPopulator db = null;
	
	/*public static void populateUsers(int noOfUsers){
		int minTimeEstimateThreshold = 5000;
		int timeEstimateInserts = 1000;
		
		// Connect to the database
		db = new MySQLDBPopulator("fakefile");
		
		// If we manage to delete and recreate the table then we can insert the users
		if(db.deleteUsers()){
			/*
			 * If we are inserting a lot of users then we'll estimate the time taken by taking an insert sample
			 
			if(noOfUsers > minTimeEstimateThreshold){
				Calendar cal = Calendar.getInstance();
				long startTime = cal.getTimeInMillis();
				
				for(int i=1; i <= timeEstimateInserts; i++){
					createUser(i);
				}
				
				cal = Calendar.getInstance();
				
				System.out.println("Estimated time remaining: " + (((cal.getTimeInMillis()-startTime)/1000.0) * ((noOfUsers-timeEstimateInserts)/(1.0 * timeEstimateInserts))) + " seconds");
			}
			else
				timeEstimateInserts = 0;
			
			/*
			 * Now we will insert the remained of the users
			 
			System.out.print("\nProgress: " + timeEstimateInserts);

			for(int i=timeEstimateInserts+1; i <= noOfUsers; i++){
				createUser(i);
				
				if(i%1000 == 0) System.out.print(" " + i);
			}
			
			System.out.println(" : total = " + noOfUsers);
			
		}
		else{
			System.out.println("PopulateUsers (populateUsers): We could not drop and recreate the table");
		}
		
		// Clean up
		db.closeConnection();
	}*/
	
	public boolean makeThing(DBPopulator db, int usersInserted){
		String username = getUsername(usersInserted);
		
		return db.insertUser(getFirstName(),
				getLastName(),
				username,
				username,
				getAuthToken(),
				getEmail(username),
				getRating(),
				getStreet(),
				getTown(),
				getZip(),
				getState());
	}
	
	public boolean remakeTable(DBPopulator db){
		return db.dropAddUsers();
	}
	
	/*
	 * Make the users first name
	 */
	private static String getFirstName(){
		return "Hyong";
	}
	
	private static String getLastName(){
		return "Kim";
	}
	
	private static String getUsername(int uniqueID){
		return "Kim" + uniqueID;
	}
	
	private static String getAuthToken(){
		return "dfsdfsfs";
	}
	
	private static String getEmail(String username){
		return username + "@ece.cmu.edu";
	}
	
	private static int getRating(){
		return 1;
	}
	
	private static String getStreet(){
		return "street";
	}
	
	private static String getTown(){
		return "pitt";
	}
	
	private static String getZip(){
		return "00000-0000";
	}
	
	private static int getState(){
		return 1;
	}
}
